package cn.wolfcode.p2p.website.controller;

import cn.wolfcode.p2p.base.domain.UserInfo;
import cn.wolfcode.p2p.base.excetion.DisplayableExcetion;
import cn.wolfcode.p2p.base.service.ISystemDictionaryItemService;
import cn.wolfcode.p2p.base.service.IUserInfoService;
import cn.wolfcode.p2p.base.util.AjaxResult;
import cn.wolfcode.p2p.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BasicInfoController {

    @Autowired
    private ISystemDictionaryItemService itemService;
    @Autowired
    private IUserInfoService userInfoService;
    @RequestMapping("/basicInfo")
    public String basicInfo(Model model){
        //获取当前登录用户的账户个人信息
        //model.addAttribute("loginInfo", UserContext.getCount());
        //用户的基本信息
        model.addAttribute("userInfo", userInfoService.getCurrent());
        //educationBackgrounds
        model.addAttribute("educationBackgrounds",itemService.selectByDictionSn("educationBackground"));
        //incomeGrades
        model.addAttribute("incomeGrades",itemService.selectByDictionSn("incomeGrade"));
        //marriages
        model.addAttribute("marriages",itemService.selectByDictionSn("marriage"));
        //kidCounts
        model.addAttribute("kidCounts",itemService.selectByDictionSn("kidCount"));
        //houseConditions
        model.addAttribute("houseConditions",itemService.selectByDictionSn("houseCondition"));
        return "/basicInfo";
    }

    //保存操作
    @RequestMapping("basicInfo_save")
    @ResponseBody
    public AjaxResult basicInfoSave(UserInfo userInfo){
        AjaxResult result = null;
        try {
            userInfoService.basicInfoSave(userInfo);
            result = new AjaxResult();
        } catch (DisplayableExcetion e) {
            e.printStackTrace();
            result = new AjaxResult(false, e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult(false,"系统出错,请联系管理员");
        }
        return result;
    }



}
